package com.demo.aop.controller;

import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试 Controller
 *
 * @author yueyang
 * @since 2022-03-01 11:02:00
 */
@Slf4j
@RestController
public class TestController {

  /**
   * 测试方法
   *
   * @param who 测试参数
   * @return {@link Dict}
   */
  @GetMapping("/test")
  public Dict test(String who) {
    return Dict.create().set("who", StrUtil.isBlank(who) ? "me" : who);
  }

  /**
   * 测试post json方法
   *
   * @param map 请求的json参数
   * @return {@link Dict}
   */
  @PostMapping("/testJson")
  public Dict testJson(@RequestBody Map<String, Object> map) {

    final String jsonStr = JSONUtil.toJsonStr(map);
    log.info(jsonStr);
    return Dict.create().set("json", map);
  }
}
